package com.zhongjiananbang.mytext;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.zhongjiananbang.standardlibeary.RenInterface;

/**
 * 基类 插件跳转
 * Created by renjibo on 2017/11/15.
 */

public class BaseActivity extends Activity implements RenInterface {
    protected Activity baseContext;//上下文--系统不能用


    //关于上下文方法都重写
    @Override
    public void attach(Activity activity) {
        this.baseContext = activity;
        Log.d("aa------", "BaseActivity attach");
    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        if (baseContext == null) {
            super.setContentView(layoutResID);
        } else {
            baseContext.setContentView(layoutResID);
        }
    }

    @Override
    public <T extends View> T findViewById(int id) {
        if (baseContext == null) {
            return super.findViewById(id);
        } else {
            return baseContext.findViewById(id);
        }
    }

    @Override
    public ClassLoader getClassLoader() {
        if (baseContext == null) {
            return super.getClassLoader();
        } else {
            return baseContext.getClassLoader();
        }
    }

    @NonNull
    @Override
    public LayoutInflater getLayoutInflater() {
        if (baseContext == null) {
            return super.getLayoutInflater();
        } else {
            return baseContext.getLayoutInflater();
        }
    }

    @Override
    public Window getWindow() {
        if (baseContext == null) {
            return super.getWindow();
        } else {
            return baseContext.getWindow();
        }
    }

    @Override
    public WindowManager getWindowManager() {
        if (baseContext == null) {
            return super.getWindowManager();
        } else {
            return baseContext.getWindowManager();
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

    }

    @Override
    public void onStart() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onStop() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void onRestart() {

    }

    @Override
    public void onResume() {

    }

    @Override
    public void startActivity(Intent intent) {
        Intent newIntent = new Intent();
        newIntent.putExtra("className", intent.getComponent().getClassName());
        baseContext.startActivity(newIntent);
    }
}
